package com.yehui.spring.applicationContext;

import org.springframework.context.annotation.AnnotationConfigApplicationContext;
import org.springframework.context.event.ContextStoppedEvent;
import org.springframework.context.event.EventListener;
import org.springframework.stereotype.Component;

import java.io.IOException;

/**
 * @author 业徽
 * @date 2021/6/28
 */
@Component
public class ShutDownHookDemo {

    @EventListener
    public void contextRefreshedEvent(ContextStoppedEvent event) {
        System.out.println("ContextStoppedEvent");
    }

    public static void main(String[] args) throws IOException {
        final AnnotationConfigApplicationContext applicationContext = new AnnotationConfigApplicationContext();
        applicationContext.register(ShutDownHookDemo.class);

        applicationContext.registerShutdownHook();
        applicationContext.refresh();


        System.in.read();
    }

}
